<!--
 * @FilePath     : /study_code/vue2.x/component-child-2-parent.html
 * @Description  : 子向父传参
 * @Date         : 2025-05-02 17:44:05
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-02 17:44:20
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="app">
      <my-component @enlarge-text="updateValueParent"></my-component>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>
    <script>
      // 自定义组件
      const myComponent = {
        data: function () {
          return {}
        },
        props: [],
        template: `
      <button @click="updateValueChild">Enlarge text</button>
      `,
        methods: {
          // 事件处理：更新父组件数据
          updateValueChild() {
            this.$emit('enlarge-text', 'newValueText')
          },
        },
      }

      var app = new Vue({
        el: '#app',
        data: function () {
          return {
            value: 'oldValueText',
          }
        },
        components: {
          myComponent,
        },
        methods: {
          // 父组件自定义事件绑定的方法
          updateValueParent(newVal) {
            this.value = newVal
            console.log('父组件更新后的值', this.value)
          },
        },
      })
    </script>
  </body>
</html>
